package com.itheima.day27;

import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

@WebServlet("/picture")
public class PictureAdd extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置传输的类型
        resp.setContentType("image/jpeg");
        //获得图片的输入流
        InputStream resourceAsStream = PictureAdd.class.getResourceAsStream("/招式.jpg");
        //获得响应输出流
        ServletOutputStream outputStream = resp.getOutputStream();
        //向网页写入图片
        IOUtils.copy(resourceAsStream, outputStream);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
